const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const Message = sequelize.define('Message', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    content: {
        type: DataTypes.TEXT,
        allowNull: false
    },
    senderId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: 'Users',
            key: 'id'
        }
    },
    receiverId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: 'Users',
            key: 'id'
        }
    },
    type: {
        type: DataTypes.ENUM('TEXT', 'EMOJI', 'RECALLED', 'QUOTE', 'IMAGE', 'AUDIO', 'FILE', 'VIDEO'),
        defaultValue: 'TEXT'
    },
    isDelivered: {
        type: DataTypes.BOOLEAN,
        defaultValue: false
    },
    isRead: {
        type: DataTypes.BOOLEAN,
        defaultValue: false
    },
    readTime: {
        type: DataTypes.DATE,
        allowNull: true
    },
    timestamp: {
        type: DataTypes.DATE,
        defaultValue: DataTypes.NOW
    },
    quotedMessageId: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: {
            model: 'Messages',
            key: 'id'
        }
    },
    quotedContent: {
        type: DataTypes.TEXT,
        allowNull: true
    },
    quotedSenderName: {
        type: DataTypes.STRING,
        allowNull: true
    },
    imageUrl: {
        type: DataTypes.STRING,
        allowNull: true
    },
    audioUrl: {
        type: DataTypes.STRING,
        allowNull: true
    },
    audioDuration: {
        type: DataTypes.INTEGER,
        allowNull: true
    },
    fileUrl: {
        type: DataTypes.STRING,
        allowNull: true
    },
    fileName: {
        type: DataTypes.STRING,
        allowNull: true
    },
    fileSize: {
        type: DataTypes.BIGINT,
        allowNull: true
    },
    videoUrl: {
        type: DataTypes.STRING,
        allowNull: true
    },
    videoDuration: {
        type: DataTypes.INTEGER,
        allowNull: true
    },
    videoThumbnail: {
        type: DataTypes.STRING,
        allowNull: true
    }
});

module.exports = Message; 